import { delay } from 'lodash'
export let sqlSet = new Set()

export default (config, request) => {
  if (config.data && config.data.type && config.data.type === 'widget') {
    return new Promise((resolve, reject) => {
      request(config).then(res => {
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  }
  sqlSet.add(sqlSet.size + 1)
  return new Promise((resolve, reject) => {
    delay(() => {
      request(config).then(res => {
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    }, (sqlSet.size - 1) * 100)
  })
}
